import React from 'react';

import emitter from './events';

class OneList extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            message: 'OneList'
        }
    }

    componentDidMount() {
        this.eventsEmitter = emitter.addListener('changeMessage', (message) => {
            this.setState({
                message
            })
        })
        // console.log(this.eventsEmitter);
        // this.eventsEmitter = emitter.on('changeMessage', (message) => {
        //     this.setState({
        //         message
        //     })
        // })
    }

    componentWillUnmount() {
        // console.log(this.eventsEmitter);
        emitter.removeListener(this.eventsEmitter)
        // emitter.removeAllListeners(this.eventsEmitter)
        // emitter.off(this.eventsEmitter)
    }

    render() {
        return (
            <>
                {this.state.message}
            </>
        )
    }
}

export default OneList